#include "head.h"

int ls(me_t* me, int sock_fd, char* cmd)
{
    messenger_t msg;
    bzero(&msg, sizeof(msg));

    msg.cmd = LS;
    while(*cmd++ != ' ');
    sprintf(msg.args, "%s", me->path);
    sprintf(msg.token, "%s", me->token);
    
    send(sock_fd, &msg, sizeof(msg), MSG_NOSIGNAL);

    while(1)
    {
        char name[200] = {0};
        char type[10] = {0};
        char size[20] = {0};
        int count = recv(sock_fd, name, sizeof(name), MSG_WAITALL);
        if(count == 0)
            break;
        recv(sock_fd, type, sizeof(type), MSG_WAITALL);
        recv(sock_fd, size, sizeof(size), MSG_WAITALL);
        if(strcmp(type, "1") == 0)
            printf("\033[34m%s\033[0m ", name);
        else
            printf("%s ", name);
    }

    printf("输出完成\n");
    close(sock_fd);
    return 0;
}